local nya__xianzhou = fk.CreateSkill {

  name = "nya__xianzhou",

  tags = { Skill.Limited, },

}



nya__xianzhou:addEffect("active", {
  name = "nya__xianzhou",
  anim_type = "control",
  min_card_num = 0,
  target_num = 1,
  frequency = Skill.Limited,
  prompt = "#nya__xianzhou",
  can_use = function(self, player)
    return player:usedSkillTimes(nya__xianzhou.name, Player.HistoryGame) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return true
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local n = #effect.cards
    local dummy = Fk:cloneCard("dilu")
    dummy:addSubcards(effect.cards)
    room:obtainCard(target, dummy, false, fk.ReasonGive)
    if target.dead then return end
    local targets = table.map(table.filter(room:getOtherPlayers(target), function(p)
      return target:inMyAttackRange(p) end), function(p) return p.id end)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(target, targets, 1, n, "#xianzhou-choose:"..player.id.."::"..n, nya__xianzhou.name, true)
      if #tos > 0 then
        for _, p in ipairs(tos) do
          room:damage{
            from = target,
            to = room:getPlayerById(p),
            damage = 1,
            skillName = nya__xianzhou.name,
          }
        end
      else
        if player:isWounded() and not player.dead then
          room:recover({
            who = player,
            num = math.min(n, player:getLostHp()),
            recoverBy = target,
            skillName = nya__xianzhou.name
          })
        end
      end
    end
  end,
})

nya__xianzhou:addEffect(fk.EventAcquireSkill, {
  name = "#nya__xianzhou_trigger",
  mute = true,
  events = {fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:usedSkillTimes("nya__xianzhou", Player.HistoryGame) > 0 and data.name == "nya__play"
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    player:setSkillUseHistory("nya__xianzhou", 0, Player.HistoryGame)
  end,
})

return nya__xianzhou